<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '新增' : '查看'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    :modal="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="注册时间::">
              <span>{{dataForm.addTime}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="营业时间:" prop="msn">
              <el-input v-model="dataForm.msn" placeholder="营业时间"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员名称:" prop="trueName">
              <el-input v-model="dataForm.trueName" placeholder="会员名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员账号:" prop="username">
              <el-input v-model="dataForm.username" placeholder="会员账号"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员负责人:" prop="realName">
              <el-input v-model="dataForm.realName" placeholder="会员负责人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员类型:">
              <span>{{dataForm.userType}}</span>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员Mobile:" prop="mobile">
              <el-input v-model="dataForm.mobile" placeholder="会员Mobile"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员描述:" prop="description">
              <el-input v-model="dataForm.description" placeholder="会员描述"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员主图:">
                <img :src="'http://image.yilianbaihui.cn/consumer/'+ dataForm.path + '/' + dataForm.name" style="max-height: 30px;max-width: 80px" v-if="dataForm.path != null && dataForm.name != null">
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="营业证件:">
                <img :src="'http://image.yilianbaihui.cn/consumer/' + dataForm.licensePic" placeholder="营业证件" style="max-height: 30px;max-width: 80px" v-if="dataForm.licensePic != null">
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="审核意见:" prop="checkComment">
              <el-input v-model="dataForm.checkComment" placeholder="审核意见"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员地址:" prop="address">
              <el-input v-model="dataForm.address" placeholder="会员地址"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="现金券余额:">
              <span>{{dataForm.integral}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="推广余额:">
              <span>{{dataForm.commissionMoney}}</span>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="总金额/元:">
              <span>{{dataForm.balanceMoney}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="未提现/元:">
              <span>{{dataForm.notExtract}}</span>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="已提现/元:">
              <span>{{dataForm.yesExtract}}</span>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="上级名称:">
              <span>{{dataForm.paTrueName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="上级账号:">
              <span>{{dataForm.paUserName}}</span>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="上级负责人:">
              <span>{{dataForm.paRealName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="上级类型:">
              <span>{{dataForm.paUserType}}</span>
            </el-form-item>
          </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        isDisabled: false,
        visible: false,
        dialogImageUrl: '',
        dialogVisible: false,
        dataForm: {
          id: 0,
          addTime: '',
          msn: '',
          username: '',
          trueName: '',
          realName: '',
          mobile: '',
          checkComment: '',
          address: '',
          description: '',
          userType: '',
          integral: '',
          commissionMoney: '',
          balanceMoney: '',
          notExtract: '',
          yesExtract: '',
          paTrueName: '',
          paUserName: '',
          paRealName: '',
          paUserType: '',
          path: '',
          name: '',
          licensePic: '',
          imgs: []
        },
        dataRule: {}
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.isDisabled = false
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/user/finance/getFinanceById/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.id = data.data.id
                this.dataForm.addTime = data.data.addTime
                this.dataForm.msn = data.data.msn
                this.dataForm.username = data.data.username
                this.dataForm.trueName = data.data.trueName
                this.dataForm.realName = data.data.realName
                this.dataForm.mobile = data.data.mobile
                this.dataForm.checkComment = data.data.checkComment
                this.dataForm.address = data.data.address
                this.dataForm.description = data.data.description
                this.dataForm.userType = data.data.userType
                this.dataForm.integral = data.data.integral
                this.dataForm.commissionMoney = data.data.commissionMoney
                this.dataForm.balanceMoney = data.data.balanceMoney
                this.dataForm.notExtract = data.data.notExtract
                this.dataForm.yesExtract = data.data.yesExtract
                this.dataForm.paTrueName = data.data.paTrueName
                this.dataForm.paUserName = data.data.paUserName
                this.dataForm.paRealName = data.data.paRealName
                this.dataForm.paUserType = data.data.paUserType
                this.dataForm.licensePic = data.data.licensePic
                this.dataForm.name = data.data.name
                this.dataForm.path = data.data.path
                // this.dataForm.imgs.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/' + data.data.path + '/' + data.data.name})
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.isDisabled = true
            this.$http({
              url: this.$http.adornUrl(`/user/finance/modifyFinanceById`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'realName': this.dataForm.realName,
                'username': this.dataForm.username,
                'mobile': this.dataForm.mobile,
                'trueName': this.dataForm.trueName,
                'msn': this.dataForm.msn,
                'address': this.dataForm.address,
                'checkComment': this.dataForm.checkComment,
                'description': this.dataForm.description
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
